package com.mySpringMvc.web.servlet.view;

import com.mySpringMvc.web.servlet.View;
import com.mySpringMvc.web.servlet.ViewResolver;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Locale;

/**
 * @program: mySSM
 * @description: 内部资源视图处理器,可以用于jsp的解析
 * @author:wjp
 * @create: 2025-02-13 18:26
 **/
@NoArgsConstructor
@AllArgsConstructor
public class InternalResourceViewResolver implements ViewResolver {

    private String prefix;

    private String suffix;

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getSuffix() {
        return suffix;
    }

    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    @Override
    public View resolveViewName(String viewName, Locale locale) throws Exception {
        InternalResourceView internalResourceView = new InternalResourceView();
        internalResourceView.setContentType("text/html;charset=UTF-8");
        // 将逻辑视图名称转换为物理视图名称
        internalResourceView.setPath(prefix + viewName + suffix);
        return internalResourceView;
    }
}
